<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/04/20 22:22:40 $)
// $RCSfile: cli_parser.php,v $ : $Revision: 1.14 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

define("INPARSER", "1");

$template->loadLanguageSection("emailparser");
$template->loadLanguageSection("staff_tickets");
$template->loadLanguageSection("tickets_auditlogs");
require_once ("./includes/functions_mime.php");
require_once ("./includes/functions_users.php");

$_SWIFT["startparser"] = fetchmicrotime();

if ($module->isRegistered(MODULE_TICKETS))
{
	require_once ("./modules/tickets/functions_ticketcore.php");
	require_once ("./modules/tickets/functions_ticketmain.php");
	require_once ("./modules/tickets/functions_alertrules.php");
	require_once ("./modules/tickets/functions_attachments.php");
	require_once ("./modules/tickets/functions_search.php");
	require_once ("./modules/tickets/functions_sla.php");
}

if (!empty($_SWIFT["clifileload"]))
{
	$data = implode("", file($_SWIFT["clifileload"]));
} else {
	// Parse incoming data
	$fp = @fopen("php://stdin", "r");
	if ($fp > 0)
	{ 
		while(!feof($fp))
		{ 
			$data .= fgets($fp, 120);
		}
	}

	fclose($fp);

//	$data = implode("", file("/tmp/test.txt"));
}

require_once ("./modules/parser/functions_parsercore.php");
require_once ("./modules/parser/functions_parserrules.php");

if (trim($data) != "")
{
	parserDebug("STDIN: Received data, Sending it for processing");
	parseRawMimeData($data);
} else {
	parserDebug("STDIN: No Data Received, Shutting Down...");
}

if (!empty($_SWIFT["clifileload"]) && $_SWIFT["clidebug"])
{
//	echo $_SWIFT["debugdata"];
}
?>